<!doctype html>
<html> 

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="../css/font-awesome.min.css" />
		<link rel="stylesheet" href="../css/bootstrap.min.css" />
		<link rel="stylesheet" href="../css/index.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>
	<style>
		body {
			background: #f0f0f0;
		}
		
		.container-fill {
			padding: .5em;
		}
		
		.text-muted {
			color: #ddd;
		}
		
		.text-orange {
			color: #f15a0c;
		}
		
		h4 {
			margin: 5px 0;
		}
		
		h4:first-of-type {
			margin-top: 10px;
		}
		
		.panel {
			padding: .5em;
			margin-bottom: 10px;
		}
		
		.nav.nav-tabs {
			margin-bottom: .8em;
			background: white;
			padding-top: .8em;
		}
		
		.alert .form-group {
			margin-bottom: 0;
		}
		
		label.form-group {
			display: block;
		}
		
		label.form-group {
			font-weight: normal;
			overflow: hidden;
			border-top: 1px #DDD solid;
			padding-top: 10px;
			padding-bottom: 0;
			margin-bottom: 0
		}
		
		label.form-group .col-xs-2 {
			margin-top: 0px;
		}
		
		label.form-group .col-xs-2 i {
			margin-top: 10px;
		}
		
		label.form-group input[name="type"] {
			opacity: 0;
			width: 0;
		}
		
		.pay-info p.bb {
			border-top: 1px #ddd dashed;
			padding: 10px 5px 0px;
		}
		
		.pay-info p.b1 {
			padding: 0px 5px;
			font-size: 15px;
		}
		
		a.btn.btn-block.js-pay {
			margin: 12px 0;
		}
		#pay_money{outline: none;}
	</style>
	<form action="index.php?c=member&a=cash" id="form1" method="post">
		<div class="index_sjlisbt clearfix dianpu"><i></i>订单信息</div>
		<div class="panel">
			<div class="clearfix pay-info" style="padding-top:10px;">
				<p class="b1">商品名称 :<span class="pull-right">面对面收款</span></p>
				<p class="bb">订单编号 :<span class="pull-right" id="order_no">{$paylog['sn']}</span></p>
				<p class="bb">收款商家 :<span class="pull-right" id="agent_name">龙信云商铺</span></p>
				<!--<p class="bb">买家名称 :<span class="pull-right" id="user_name"></span></p>-->
				<p class="bb">支付金额 :<span class="pull-right" >￥<input type="text" id="pay_money">元</span></p>
			</div>
		</div>
		<div class="index_sjlisbt clearfix dianpu"><i></i>选择支付方式</div>
		<ul class="nav nav-tabs" role="tablist" style="margin-bottom:0;">
			<li class="active" data-id="direct">
				<a href="#direct" role="tab" data-toggle="tab" style="border-left:0;">直接到账</a>
			</li>
		</ul>
		<div class="panel" style="border-top-left-radius:0; border-top-right-radius:0;">
			<div class="tab-content">
				<div class="tab-pane animated active fadeInLeft" id="direct">
					<div class="clearfix">
						<a class="btn btn-info btn-block js-pay js-m" data-type="3" href="javascript:;">支付宝支付</a>
						<a class="btn btn-success btn-block js-pay js-m js-wx" data-type="2" href="javascript:;">微信支付</a>
					<!--	<a class="btn btn-warning btn-block js-pay js-m" data-type="4" href="javascript:;">银联支付</a>-->
					</div>
				</div>
			</div>
		</div>
		<!--<input type="hidden" name="paytype" value="" id="pay-type">
		<input type="hidden" name="params" value="">
		<input type="hidden" name="type" value="">-->
			<input type="hidden" id="post_sn">
			<input type="hidden" id="post_money">
			<input type="hidden" id="store_id">
			<input type="hidden" id="cut_pay_type">
			<input type="hidden" id="pay_status">
			
			<div id="cut_back"></div>
	</form>
	<div id="callback"></div>
	</body>
	<script type="text/javascript" src="../js/date.js"></script>

	<script type="text/javascript" src="../js/jquery.min.js"></script>
	<script type="text/javascript" src="../js/layer/layer.min.js"></script>
		<script type="text/javascript" src="../js/app.js"></script>
	<script>
    	var ua = navigator.userAgent.toLowerCase();  
	    if(ua.match(/MicroMessenger/i)=="micromessenger") {  
	    } else {  
	    	$(".js-wx").text("微信支付(仅限微信浏览器)");
	    }  
  
		$(function() {
			checkLogin(APP.web_root+"member/login.html");
			var member = JSON.parse(localStorage.getItem('member'));
			//获取商户信息
			$.ajax({
				url: APP.api_url + 'Wallet/agent_shou',
				data: {
					uid			: getUid(),
					token 		: get_token(),
					agent_id 	: getUrlParam('getmoney_uid')
				},
				//type: "post",
				success: function(data) {
					var store_info = data.data;
					$("#order_no").text(store_info['sn']);
					$("#agent_name").text(store_info['store_name']);
					$("#store_id").val(store_info['id']);
				}
			})
			$(".btn-primary").click(function() {
				$(".modal").addClass("in");
				$(".modal").show();
			})
			$(".js-m").click(function() {
				var pay_type=$(this).data("type");
				$("#cut_pay_type").val(pay_type);
				
				var act="alipay";
				var jstype="html";
				var openid=member['openid'];
				if(openid==""){
					openid=localStorage.getItem("openid");
				}
				if(pay_type==2){
					act="wechat";
					jstype="jsonp";
				}else if(pay_type==4){
					act="unionpay";
				}
				$.ajax({
					url: APP.api_url + 'Payment/'+act,
					data: {
						WIDout_trade_no	: $("#order_no").text(),
						WIDsubject		: "面对面收款",
						WIDtotal_fee	: $("#pay_money").val(),
						return_url		: APP.web_root+"member/index.html",
						WIDshow_url		: 'www',
						WIDbody			: '面对面收款授权支付',
						uid				: getUid(),
						type			: "gathering",
						user_type		: member['agent_type'],
						order_id		: $("#store_id").val(),
						token			: get_token(),
						openid			: openid,
						pay_type		: pay_type
					},
					type: "post",
					dataType:jstype,
					jsonp:'callback',  
					jsonpCallback :'jsonpCallback',
					success: function(data) {
						$("#post_sn").val($("#order_no").text()); 
						$("#post_money").val($("#pay_money").val());
						if(pay_type==2){
							callpay(data);
						}else{
							$("#callback").append(data);
						}
						if(pay_type==4){
							$("#pay_form").submit();
						}
					}
				})
			})
		function jsonpCallback(data){
			
			$("#cut_back").append(data);
		}
			//调用微信JS api 支付
		function jsApiCall(jsApiParameters) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
				function(res) {
					if(res.err_msg == "get_brand_wcpay_request:ok") {
						$("#pay_status").val(2);
						alert('支付成功');
					} else {
						$("#pay_status").val(1);
						alert('支付失败');
					}
					print_log();
				}
			);
		}

		function callpay(jsApiParameters) {
			console.log(jsApiParameters);
			if(typeof WeixinJSBridge == "undefined") {
				if(document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
				} else if(document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
				}
			} else {
				jsApiCall(jsApiParameters);
			}
		}
		
		
		
		//打印日志
	function print_log(){
		$.ajax({
				url: APP.api_url + 'Wallet/add_paylog',
				data: {
					uid 		: getUid(),
					token		: get_token(),
					type		: "gathering",
					sn			: $("#order_no").text(),
					user_type	: member['agent_type'],
					pay_type	: $("#cut_pay_type").val(),
					tid			: $("#store_id").val(),
					price		: $("#pay_money").val(),
					status		: $("#pay_status").val()
				},
				//type: "post",
				success: function(data) {
					if(dat.code==200){
						alert("日志打印成功")
					}else{
						alert(data.msg);
					}
				}
			})
	}
})
	</script>
</html>

